<!-- HTML header for doxygen 1.9.1-->
<!DOCTYPE html
    PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=9" />
    <meta name="generator" content="Doxygen 1.9.4" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <title>NumCpp: InterfaceWithOpenCV.cpp</title>
    <link href="tabs.css" rel="stylesheet" type="text/css" />
    <script type="text/javascript" src="jquery.js"></script>
    <script type="text/javascript" src="dynsections.js"></script>
    <link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtreedata.js"></script>
<script type="text/javascript" src="navtree.js"></script>
    <link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
    <link href="doxygen.css" rel="stylesheet" type="text/css" />
    <link href="doxygen-awesome.css" rel="stylesheet" type="text/css"/>
<link href="doxygen-awesome-sidebar-only-darkmode-toggle.css" rel="stylesheet" type="text/css"/>
    <!-- ... other metadata & script includes ... -->
    <script type="text/javascript" src="../doxygen-awesome-css/doxygen-awesome-darkmode-toggle.js"></script>
    <script type="text/javascript">
        DoxygenAwesomeDarkModeToggle.init()
    </script>
    <script type="text/javascript"
        src="../doxygen-awesome-css/doxygen-awesome-fragment-copy-button.js"></script>
    <script type="text/javascript">
        DoxygenAwesomeFragmentCopyButton.init()
    </script>
    <script type="text/javascript" src="../doxygen-awesome-css/doxygen-awesome-paragraph-link.js"></script>
    <script type="text/javascript">
        DoxygenAwesomeParagraphLink.init()
    </script>
    <script type="text/javascript" src="../doxygen-awesome-css/doxygen-awesome-interactive-toc.js"></script>
    <script type="text/javascript">
        DoxygenAwesomeInteractiveToc.init()
    </script>
</head>
<body>
    <div id="top">
        <!-- do not remove this div, it is closed by doxygen! -->
        <div id="titlearea">
            <table cellspacing="0" cellpadding="0">
                <tbody>
                    <tr style="height: 56px;">
                        <td id="projectlogo"><img alt="Logo" src="NumCppLogoDoxygen.png" /></td>
                        <td id="projectalign" style="padding-left: 0.5em;">
                            <div id="projectname">NumCpp
                                &#160;<span id="projectnumber">2.12.1</span>
                            </div>
                            <div id="projectbrief">A Templatized Header Only C++ Implementation of the Python NumPy Library</div>
                        </td>
                    </tr>
                </tbody>
            </table>
        </div>
        <!-- end header part --><!-- Generated by Doxygen 1.9.4 -->
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;dn=expat.txt MIT */
var searchBox = new SearchBox("searchBox", "search",'Search','.html');
/* @license-end */
</script>
<script type="text/javascript" src="menudata.js"></script>
<script type="text/javascript" src="menu.js"></script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;dn=expat.txt MIT */
$(function() {
  initMenu('',true,false,'search.php','Search');
  $(document).ready(function() { init_search(); });
});
/* @license-end */
</script>
<div id="main-nav"></div>
</div><!-- top -->
<div id="side-nav" class="ui-resizable side-nav-resizable">
  <div id="nav-tree">
    <div id="nav-tree-contents">
      <div id="nav-sync" class="sync"></div>
    </div>
  </div>
  <div id="splitbar" style="-moz-user-select:none;" 
       class="ui-resizable-handle">
  </div>
</div>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;dn=expat.txt MIT */
$(document).ready(function(){initNavTree('_interface_with_open_c_v_8cpp-example.html',''); initResizable(); });
/* @license-end */
</script>
<div id="doc-content">
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

<div class="header">
  <div class="headertitle"><div class="title">InterfaceWithOpenCV.cpp</div></div>
</div><!--header-->
<div class="contents">
<p >Example for interfaceing with OpenCV Mat</p>
<div class="fragment"><div class="line"><span class="preprocessor">#include &quot;<a class="code" href="_num_cpp_8hpp.html">NumCpp.hpp</a>&quot;</span></div>
<div class="line"><span class="preprocessor">#include &quot;opencv2/core/core.hpp&quot;</span></div>
<div class="line"><span class="preprocessor">#include &quot;opencv2/highgui/highgui.hpp&quot;</span></div>
<div class="line"> </div>
<div class="line"><span class="preprocessor">#include &lt;iostream&gt;</span></div>
<div class="line"><span class="preprocessor">#include &lt;numeric&gt;</span></div>
<div class="line"> </div>
<div class="line"> </div>
<div class="line"><span class="keyword">constexpr</span> <a class="code hl_typedef" href="namespacenc.html#af0f49663fb63332596e2e6327009d581">nc::uint32</a> NUM_ROWS = 512;</div>
<div class="line"><span class="keyword">constexpr</span> <a class="code hl_typedef" href="namespacenc.html#af0f49663fb63332596e2e6327009d581">nc::uint32</a> NUM_COLS = 512;</div>
<div class="line"> </div>
<div class="line"><span class="keywordtype">int</span> main()</div>
<div class="line">{</div>
<div class="line">    <span class="comment">// create a ramp image with NumCpp</span></div>
<div class="line">    <span class="keyword">constexpr</span> <span class="keyword">auto</span> numHalfCols = NUM_COLS / 2; <span class="comment">// integer division</span></div>
<div class="line">    <span class="keyword">auto</span>           ncArray     = <a id="_a0" name="_a0"></a><a class="code hl_class" href="classnc_1_1_nd_array.html">nc::NdArray&lt;nc::uint8&gt;</a>(NUM_ROWS, NUM_COLS);</div>
<div class="line">    <span class="keywordflow">for</span> (<a class="code hl_typedef" href="namespacenc.html#af0f49663fb63332596e2e6327009d581">nc::uint32</a> row = 0; row &lt; ncArray.numRows(); ++row)</div>
<div class="line">    {</div>
<div class="line">        <span class="keyword">auto</span> begin = ncArray.begin(row);</div>
<div class="line">        std::iota(begin, begin + numHalfCols, <a class="code hl_typedef" href="namespacenc.html#a9ba5a0aa26753a185985b8273fb9062d">nc::uint8</a>{ 0 });</div>
<div class="line"> </div>
<div class="line">        <span class="keyword">auto</span> rbegin = ncArray.rbegin(row);</div>
<div class="line">        std::iota(rbegin, rbegin + numHalfCols, <a class="code hl_typedef" href="namespacenc.html#a9ba5a0aa26753a185985b8273fb9062d">nc::uint8</a>{ 0 });</div>
<div class="line">    }</div>
<div class="line"> </div>
<div class="line">    <span class="comment">// convert to OpenCV Mat</span></div>
<div class="line">    <span class="keyword">auto</span> cvArray = cv::Mat(ncArray.numRows(), ncArray.numCols(), CV_8SC1, ncArray.data());</div>
<div class="line"> </div>
<div class="line">    <span class="comment">// display the OpenCV Mat</span></div>
<div class="line">    cv::namedWindow(<span class="stringliteral">&quot;Display window&quot;</span>, cv::WINDOW_AUTOSIZE); <span class="comment">// Create a window for display.</span></div>
<div class="line">    cv::imshow(<span class="stringliteral">&quot;Display window&quot;</span>, cvArray);                  <span class="comment">// Show our image inside it.</span></div>
<div class="line">    cv::waitKey(0);                                         <span class="comment">// Wait for a keystroke in the window</span></div>
<div class="line"> </div>
<div class="line">    <span class="comment">// tranpose the Mat with OpenCV</span></div>
<div class="line">    <span class="keyword">auto</span> transposedCvArray = cv::Mat(cvArray.cols, cvArray.rows, CV_8SC1);</div>
<div class="line">    <a id="a1" name="a1"></a><a class="code hl_function" href="namespacenc.html#af5bc0015bc8f7e29d7eba3c17ec139b4">cv::transpose</a>(cvArray, transposedCvArray);</div>
<div class="line"> </div>
<div class="line">    <span class="comment">// display the transposed Mat</span></div>
<div class="line">    cv::namedWindow(<span class="stringliteral">&quot;Display window&quot;</span>, cv::WINDOW_AUTOSIZE); <span class="comment">// Create a window for display.</span></div>
<div class="line">    cv::imshow(<span class="stringliteral">&quot;Display window&quot;</span>, transposedCvArray);        <span class="comment">// Show our image inside it.</span></div>
<div class="line">    cv::waitKey(0);                                         <span class="comment">// Wait for a keystroke in the window</span></div>
<div class="line"> </div>
<div class="line">    <span class="comment">// convert the transposed OpenCV Mat to a NumCpp array</span></div>
<div class="line">    <span class="keyword">auto</span> transposedNcArray =</div>
<div class="line">        <a class="code hl_class" href="classnc_1_1_nd_array.html">nc::NdArray&lt;nc::uint8&gt;</a>(transposedCvArray.data, transposedCvArray.rows, transposedCvArray.cols);</div>
<div class="line"> </div>
<div class="line">    <span class="comment">// make sure the two transposed arrays are the same</span></div>
<div class="line">    <span class="keywordflow">if</span> (<a id="a2" name="a2"></a><a class="code hl_function" href="namespacenc.html#a0e8c1396cc01ccd9ec8ba549b6347e21">nc::array_equal</a>(transposedNcArray, ncArray.transpose()))</div>
<div class="line">    {</div>
<div class="line">        std::cout &lt;&lt; <span class="stringliteral">&quot;Arrays are equal.\n&quot;</span>;</div>
<div class="line">    }</div>
<div class="line">    <span class="keywordflow">else</span></div>
<div class="line">    {</div>
<div class="line">        std::cout &lt;&lt; <span class="stringliteral">&quot;Arrays are not equal.\n&quot;</span>;</div>
<div class="line">    }</div>
<div class="line"> </div>
<div class="line">    <span class="keywordflow">return</span> 0;</div>
<div class="line">}</div>
<div class="ttc" id="a_num_cpp_8hpp_html"><div class="ttname"><a href="_num_cpp_8hpp.html">NumCpp.hpp</a></div></div>
<div class="ttc" id="aclassnc_1_1_nd_array_html"><div class="ttname"><a href="classnc_1_1_nd_array.html">nc::NdArray</a></div><div class="ttdoc">Holds 1D and 2D arrays, the main work horse of the NumCpp library.</div><div class="ttdef"><b>Definition:</b> NdArrayCore.hpp:139</div></div>
<div class="ttc" id="anamespacenc_html_a0e8c1396cc01ccd9ec8ba549b6347e21"><div class="ttname"><a href="namespacenc.html#a0e8c1396cc01ccd9ec8ba549b6347e21">nc::array_equal</a></div><div class="ttdeci">bool array_equal(const NdArray&lt; dtype &gt; &amp;inArray1, const NdArray&lt; dtype &gt; &amp;inArray2) noexcept</div><div class="ttdef"><b>Definition:</b> array_equal.hpp:47</div></div>
<div class="ttc" id="anamespacenc_html_a9ba5a0aa26753a185985b8273fb9062d"><div class="ttname"><a href="namespacenc.html#a9ba5a0aa26753a185985b8273fb9062d">nc::uint8</a></div><div class="ttdeci">std::uint8_t uint8</div><div class="ttdef"><b>Definition:</b> Types.hpp:42</div></div>
<div class="ttc" id="anamespacenc_html_af0f49663fb63332596e2e6327009d581"><div class="ttname"><a href="namespacenc.html#af0f49663fb63332596e2e6327009d581">nc::uint32</a></div><div class="ttdeci">std::uint32_t uint32</div><div class="ttdef"><b>Definition:</b> Types.hpp:40</div></div>
<div class="ttc" id="anamespacenc_html_af5bc0015bc8f7e29d7eba3c17ec139b4"><div class="ttname"><a href="namespacenc.html#af5bc0015bc8f7e29d7eba3c17ec139b4">nc::transpose</a></div><div class="ttdeci">NdArray&lt; dtype &gt; transpose(const NdArray&lt; dtype &gt; &amp;inArray)</div><div class="ttdef"><b>Definition:</b> transpose.hpp:45</div></div>
</div><!-- fragment --> </div><!-- contents -->
</div><!-- doc-content -->
<!-- start footer part -->
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
  <ul>
    <li class="footer">Generated by <a href="https://www.doxygen.org/index.html"><img class="footer" src="doxygen.svg" width="104" height="31" alt="doxygen"/></a> 1.9.4 </li>
  </ul>
</div>
</body>
</html>
